package cn.backpackerxl.easyJDBC.util;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;

public class JSONExpression {
    private final String typeName;
    private final Typeof typeof;

    private final Object object;

    private final JSONObject jsonObject;

    private final Field field;


    public JSONExpression(String typeName, Object object, JSONObject jsonObject, Field field) {
        this.typeName = typeName;
        this.typeof = MatchType.get(typeName);
        this.object = object;
        this.jsonObject = jsonObject;
        this.field = field;
    }

    public JSONExpression(ParameterizedType parameterizedType, Object object, JSONObject jsonObject, Field field) {
        this.typeName = parameterizedType.getTypeName();
        if (this.typeName.startsWith("java.util.List")) {
            this.typeof = Typeof.LIST;
        } else if (this.typeName.startsWith("java.util.Map")) {
            this.typeof = Typeof.MAP;
        } else {
            this.typeof = null;
        }
        this.object = object;
        this.jsonObject = jsonObject;
        this.field = field;
    }

    public String getTypeName() {
        return typeName;
    }

    public Typeof getTypeof() {
        return typeof;
    }

    public Object getObject() {
        return object;
    }

    public JSONObject getJsonObject() {
        return jsonObject;
    }

    public Field getField() {
        return field;
    }
}
